const state = {
  order: null,
  cart: []
}

const mutations = {
  SAVE_ORDER: (state, data) => {
    state.order = data
  },
  SAVE_CART: (state, data) => {
    state.cart = data
  }
}

const actions = {
  async saveOredr({ commit }, data) {
    commit('SAVE_ORDER', data)
    console.log('vuex/saveOrder-log: 订单信息储存成功', data)
  },
  async clearOrder({ commit }) {
    commit('SAVE_ORDER', null)
    console.log('vuex/clearOrder-log: 订单信息清除成功')
  },
  async changeCart({ commit }, data = []) {
    commit('SAVE_CART', data)
    console.log('vuex/changeCart-log: 购物车信息变更成功', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
